//
//  InformationVC.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/5.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "InformationVC.h"
#import "InformationCell.h"
#import "Home_TypeView.h"
#import "InformationTopView.h"
#import "PredictVC.h"
#import "LabCell.h"
#import "LotteryTypeView.h"

#import "InformationVM.h"
#import "GalleryView.h"
#import "InformationLeftImageCell.h"
#import "InformationImageCell.h"
#import "LotteryVC.h"
#import "OpenLotteryRecordVC.h"
#import "AdvertisingView.h"
#import "ImageTableViewCell.h"
#import "MasterListVC.h"
#import "PlanVC.h"
#import "HomePageVM.h"
@interface InformationVC ()<UITableViewDelegate,UITableViewDataSource>
//@property (nonatomic ,strong) UIButton   *navTitleBtn;
@property (nonatomic ,strong) UITableView  *tableView;
///六合彩
@property (nonatomic ,strong) LotteryVC     *lotteryVC;
///新闻栏目列表
@property (nonatomic ,strong) NSMutableArray *newTypeArr;
@property (nonatomic ,strong) NSMutableArray *dataArr;
@property (nonatomic ,strong) Home_TypeView *home_TypeView;
@property (nonatomic ,strong) InformationTopView *topView;
@property (nonatomic ,strong) LotteryTypeView *lotteryTypeView;
@property (nonatomic ,strong) GalleryView     *galleryView;
@property (nonatomic ,assign) NSInteger   selectLottery;
@property (nonatomic ,strong) NSArray       *advertisingArr;

@property (nonatomic ,strong) AdvertisingView        *oneAdvertisingView;
@property (nonatomic ,strong) AdvertisingView        *twoAdvertisingView;


@property (nonatomic ,assign)NSInteger   page;

@property (nonatomic ,assign)NSInteger   selectNewsType;



@property (nonatomic ,strong) NSMutableArray *arr1001;
@property (nonatomic ,strong) NSMutableArray *colArr1001;




@end

@implementation InformationVC{
    
    BOOL        isData;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.page=1;
    UIBarButtonItem *rightItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_icon"] style:UIBarButtonItemStylePlain target:self action:@selector(onclickNav)];
    self.navigationItem.rightBarButtonItem=rightItem;
    
    [self getLotteryType];
}

- (void)backClick{
    if (isData) {
        [super backClick];
    }else{
        [self.navigationController popToViewController:self.saveViewController animated:YES];
    }
    [self.topView cancleTimer];
    [self.lotteryVC cancleTimer];
}

#pragma mark -- 获取彩票分类
- (void)getLotteryType{
    if (isData) {
        return;
    }
    WS(weakSelf);
    [[InformationVM manage] getNewsLotteryTypeListWithSuccess:^(id returnValue) {
        if (weakSelf.lType.length>0) {
            
            LotteryNumType  lType= [[BaseVM manage] getType:[weakSelf.lType integerValue]];
        
            for (int i=0; i<[InformationVM manage].lotteryTypeArr.count; i++) {
                NewsLottryTypeModel *model=[InformationVM manage].lotteryTypeArr[i];
                if ([model.LType integerValue]==[weakSelf.lType integerValue]) {
                    _selectLottery=i;
                    weakSelf.lType=nil;
                    break;
                }
            }
        }
//        weakSelf.navigationItem.titleView=self.navTitleBtn;
        NewsLottryTypeModel *model=[InformationVM manage].lotteryTypeArr[_selectLottery];
        if ([model.Id intValue]==5) {
            weakSelf.lotteryVC.view.hidden=NO;
            weakSelf.lotteryVC.typeModel=model;
        }else{
            weakSelf.lotteryVC.view.hidden=YES;
            [weakSelf getNewsList:model];
            [weakSelf getLotteryInfo:model];
        }
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}

- (void)setLotteryWithType:(NSInteger)type andIndex:(NSInteger)index{
    isData=YES;
    self.selectLottery=0;
    //    self.navigationItem.titleView=self.navTitleBtn;
    
    self.title = @"六合彩资讯";
    self.lotteryVC.view.hidden=YES;
    NewsLottryTypeModel *model=[InformationVM manage].lotteryTypeArr[0];
    [self getNewsList:model];
    [self getLotteryInfo:model];
    [self.lotteryTypeView setSelectLottery:index];
}

#pragma mark -- 获取新闻栏目列表
- (void)getNewsList:(NewsLottryTypeModel *)model{
    WS(weakSelf);
    [[InformationVM manage] getNewsTypeListWithId:model.Id Success:^(id returnValue) {
        weakSelf.newTypeArr=returnValue;
        [weakSelf.lotteryTypeView setDataArr:returnValue];
        if (weakSelf.index>0) {
            weakSelf.selectNewsType=weakSelf.index;
            weakSelf.index=0;
            [weakSelf.lotteryTypeView setSelectLottery:weakSelf.selectNewsType];
        }
        weakSelf.lotteryTypeView.scrollIndex=weakSelf.selectNewsType;
        [weakSelf.tableView reloadData];
        [weakSelf.tableView.header beginRefreshing];
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}

#pragma mark -- 获取彩种开奖信息
- (void)getLotteryInfo:(NewsLottryTypeModel *)model{
    WS(weakSelf);
    [[HomePageVM manage] getLotteryInfoWithId:model.LType Success:^(id returnValue) {
        [weakSelf.topView setLotteryModel:returnValue];
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}

#pragma mark-- 获取新闻列表
- (void)getNewsContentList{
    if (self.newTypeArr.count<=self.selectNewsType) {
        [self.tableView.header endRefreshing];
        return;
    }
    [SVProgressHUD show];
    
    NewsTypeModel *model=self.newTypeArr[self.selectNewsType];
    WS(weakSelf);
    if (model.ShowType==1) {
        self.galleryView.hidden=YES;
        [[InformationVM manage] getNewsListWithId:model.Id andPage:weakSelf.page Success:^(id returnValue) {
            if (weakSelf.page==1) {
                [weakSelf getAdvertising:model];
            }
            [weakSelf.dataArr addObjectsFromArray:returnValue];
            [weakSelf.tableView reloadData];
            [weakSelf.tableView.header endRefreshing];
            NSArray *arr=returnValue;
            if (arr.count<[defaultPageSize integerValue]) {
                [weakSelf.tableView.footer noticeNoMoreData];
            }else{
                [weakSelf.tableView.footer endRefreshing];
            }
            weakSelf.page+=1;
        } andFail:^(NSString *errorMessage, NSError *error) {
            [weakSelf.tableView.footer endRefreshing];
            [weakSelf.tableView.header endRefreshing];
        }];
    }else{
        [weakSelf.tableView.header endRefreshing];
        [weakSelf.tableView.footer endRefreshing];
        self.galleryView.hidden=NO;
        NewsLottryTypeModel *lModel=[InformationVM manage].lotteryTypeArr[0];
        [[InformationVM manage] getGalleryListWithId:lModel.Id andNewsTypeId:model.Id Success:^(id returnValue) {
            weakSelf.galleryView.hidden=NO;
            [weakSelf.galleryView setModel:returnValue];
            [weakSelf getAdvertising:model];
        } andFail:^(NSString *errorMessage, NSError *error) {
//            [weakSelf.tableView.footer endRefreshing];
//            [weakSelf.tableView.header endRefreshing];
        }];
    }
}
#pragma mark -- 获取广告
- (void)getAdvertising:(NewsTypeModel *)model{
    WS(weakSelf);
    [[InformationVM manage] getAdvertWithLocation:model.Id andType:1 Success:^(id returnValue) {
        weakSelf.advertisingArr=returnValue;
        [weakSelf insertAdvertising];
    } andFail:^(NSString *errorMessage, NSError *error) {
        
    }];
}
#pragma mark -- 插入广告
- (void)insertAdvertising{
    NSMutableArray *arr1=[[NSMutableArray alloc]init];
    NSMutableArray *arr2=[[NSMutableArray alloc]init];
    NSMutableArray *arr3=[[NSMutableArray alloc]init];
    NSMutableArray *arr4=[[NSMutableArray alloc]init];
    NSMutableArray *arr5=[[NSMutableArray alloc]init];
    NSMutableArray *arr6=[[NSMutableArray alloc]init];
    NSMutableArray *arr7=[[NSMutableArray alloc]init];
    NSMutableArray *arr8=[[NSMutableArray alloc]init];
    NSMutableArray *arr9=[[NSMutableArray alloc]init];
    NSMutableArray *arr10=[[NSMutableArray alloc]init];
    
    
    self.arr1001 = [NSMutableArray array];
    self.colArr1001 = [NSMutableArray array];

    for (AdvertisingModel *model in self.advertisingArr) {
        
        NSLog(@"--->%ld",model.Layer);
        if (model.Display) {
            if (model.Layer==1) {
                [arr1 addObject:model];
            }else if (model.Layer==2){
                [arr2 addObject:model];
            }else if (model.Layer==3){
                [arr3 addObject:model];
            }else if (model.Layer==4){
                [arr4 addObject:model];
            }else if (model.Layer==5){
                [arr5 addObject:model];
            }else if (model.Layer==6){
                [arr6 addObject:model];
            }else if (model.Layer==7){
                [arr7 addObject:model];
           }else if (model.Layer==8){
                [arr8 addObject:model];
            }else if (model.Layer==9){
                [arr9 addObject:model];
            }else if (model.Layer==10){
                [arr10 addObject:model];
            }else if (model.Layer==1001){
                [self.arr1001 addObject:model];
                if (model.IsDisplay) {
                    [self.colArr1001 addObject:model];

                }
            }
        
        }
    }
//    self.oneAdvertisingView.dataArr=arr1;
    self.twoAdvertisingView.dataArr=self.arr1001;
    self.twoAdvertisingView.changeHeight(self.arr1001.count*40-ceil(self.colArr1001.count/2.0)*40);
    if (self.galleryView.hidden==NO) {
        self.galleryView.arr3=arr3;
        self.galleryView.arr4=arr4;
        self.galleryView.arr5=arr5;
        self.galleryView.arr6=arr6;
    }

    if (self.dataArr.count>9) {
        [self.dataArr insertObjects:arr10 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(10, arr10.count)]];
    }
    if (self.dataArr.count>8) {
        [self.dataArr insertObjects:arr9 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(9, arr9.count)]];
    }
    if (self.dataArr.count>7) {
        [self.dataArr insertObjects:arr8 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(8, arr8.count)]];
    }
    if (self.dataArr.count>6) {
        [self.dataArr insertObjects:arr7 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(7, arr7.count)]];
    }
    if (self.dataArr.count>5) {
        [self.dataArr insertObjects:arr6 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(6, arr6.count)]];
    }
    if (self.dataArr.count>4) {
        [self.dataArr insertObjects:arr5 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(5, arr5.count)]];
    }
    if (self.dataArr.count>3) {
        [self.dataArr insertObjects:arr4 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(4, arr4.count)]];
    }
    if (self.dataArr.count>2) {
        [self.dataArr insertObjects:arr3 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(3, arr3.count)]];
    }
    if (self.dataArr.count>1) {
        [self.dataArr insertObjects:arr2 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, arr2.count)]];
    }
    if (self.dataArr.count>0) {
        [self.dataArr insertObjects:arr1 atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, arr1.count)]];
    }
    [self.tableView reloadData];
}

#pragma mark -- 点击顶部彩种分类
- (void)onclickType:(UIButton *)sender{
    if (self.home_TypeView) {
        [self.home_TypeView remove];
        self.home_TypeView=nil;
        return;
    }
    isData=NO;
    WS(weakSelf);
    self.home_TypeView=[[Home_TypeView alloc]init];
    [self.home_TypeView setNOTitleArr:[InformationVM manage].lotteryTypeArr andIndex:self.selectLottery andSelectBlock:^(NSInteger row) {
        weakSelf.selectNewsType=0;
        weakSelf.lotteryTypeView.selectLottery=0;
        weakSelf.selectLottery=row;
        weakSelf.galleryView.hidden=YES;
        weakSelf.home_TypeView=nil;
        [weakSelf getLotteryType];
    }];
    [self.view addSubview:self.home_TypeView];
    [self.home_TypeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(weakSelf.view);
    }];
}


#pragma mark -- UITableViewDelegate ,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.dataArr[indexPath.row] isKindOfClass:[NewsModel class]]) {
        NewsModel *model=self.dataArr[indexPath.row];
        if (model.ThumbStyle==0) {
            InformationCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationCell" forIndexPath:indexPath];
            [cell setModel:model];
            return cell;
        }else if (model.ThumbStyle==1){
            InformationLeftImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationLeftImageCell" forIndexPath:indexPath];
            [cell setModel:model];
            return cell;
        }else{
            InformationImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationImageCell" forIndexPath:indexPath];
            [cell setModel:model];
            return cell;
        }
    }else{
        AdvertisingModel *model=self.dataArr[indexPath.row];
        if (model.ThumbStyle==0) {
            InformationCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationCell" forIndexPath:indexPath];
            [cell setAdModel:model];
            return cell;
        }else if (model.ThumbStyle==1){
            InformationLeftImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationLeftImageCell" forIndexPath:indexPath];
            [cell setAdModel:model];
            return cell;
        }else if (model.ThumbStyle==4){
            ImageTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"ImageTableViewCell" forIndexPath:indexPath];
            if (model.ThumbList.count>0) {
                [cell.imageV sd_setImageWithURL:model.ThumbList[0] placeholderImage:[UIImage imageNamed:@"big_loding"]];
            }else{
                cell.imageV.image=[UIImage imageNamed:@"big_loding"];
            }
            
            return cell;
        }else{
            InformationImageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"InformationImageCell" forIndexPath:indexPath];
            [cell setAdModel:model];
            return cell;
        }
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([self.dataArr[indexPath.row] isKindOfClass:[NewsModel class]]) {
        NewsTypeModel *newsModel=self.newTypeArr[self.selectNewsType];
        NewsModel *model=self.dataArr[indexPath.row];
        model.TypeId=newsModel.Id;
        PredictVC   *vc=[[PredictVC alloc]init];
        vc.model=model;
        NewsLottryTypeModel *lModel=[InformationVM manage].lotteryTypeArr[self.selectLottery];
        vc.LTypeName=lModel.LTypeName;
        vc.title=[NSString stringWithFormat:@"%@.%@",lModel.LTypeName,newsModel.TypeName];
        
        vc.saveViewController=self;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        AdvertisingModel *model=self.dataArr[indexPath.row];
        
        if ([model.Title containsString:@"】"]) {
            
            UIPasteboard *copy = [UIPasteboard generalPasteboard];
            NSRange startRange = [model.Title rangeOfString:@"【"];
            NSRange endRange = [model.Title rangeOfString:@"】"];
            NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
            NSString *result = [model.Title substringWithRange:range];
            
            [copy setString:result];
            
            [SVProgressHUD showSuccessWithStatus:@"复制成功"];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [SVProgressHUD dismiss];
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString: @"weixin://"]];
            });
            
        }else{
            
            if (model.TransferUrl.length<1) {
                return;
            }
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString: model.TransferUrl]];
            
        }
    }
}

#pragma mark -- 懒加载
- (UITableView *)tableView{
    if (!_tableView) {
        WS(weakSelf);
        _tableView=[[UITableView alloc]init];
        _tableView.dataSource=self;
        _tableView.delegate=self;
        _tableView.backgroundColor=DEFAULTBGCOLOR;
        [_tableView registerClass:[InformationCell class] forCellReuseIdentifier:@"InformationCell"];
        [_tableView registerClass:[InformationLeftImageCell class] forCellReuseIdentifier:@"InformationLeftImageCell"];
        [_tableView registerClass:[InformationImageCell class] forCellReuseIdentifier:@"InformationImageCell"];
        [_tableView registerClass:[ImageTableViewCell class] forCellReuseIdentifier:@"ImageTableViewCell"];
        
        _tableView.estimatedRowHeight=150.0f;
        _tableView.rowHeight=UITableViewAutomaticDimension;
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _tableView.header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
            weakSelf.page=1;
            [weakSelf.dataArr removeAllObjects];
            [weakSelf.tableView reloadData];
            [weakSelf getNewsContentList];
        }];
        _tableView.footer=[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            [weakSelf getNewsContentList];
        }];
        [self.view addSubview:_tableView];
        
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(weakSelf.view);
            make.top.equalTo(weakSelf.lotteryTypeView.mas_bottom)
            .with.offset(1);
        }];
    
    }
    return _tableView;
}

- (NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr=[[NSMutableArray alloc]init];
    }
    return _dataArr;
}




- (InformationTopView *)topView{
    if (!_topView) {
        _topView=[[InformationTopView alloc] initWithModel:[[Home_LotteryModel alloc]init]];
        [self.view addSubview:_topView];
        [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self.view);
//            make.top.equalTo(self.oneAdvertisingView.mas_bottom);
            make.height.mas_equalTo(@(real_size(123)));
        }];
    }
    return _topView;
}

- (LotteryTypeView *)lotteryTypeView{
    if (!_lotteryTypeView) {
        WS(weakSelf);
        _lotteryTypeView=[[LotteryTypeView alloc]init];
        _lotteryTypeView.chaneBlock = ^(NSInteger row) {
            if (weakSelf.selectNewsType!=row) {
                weakSelf.selectNewsType=row;
                weakSelf.galleryView.hidden=YES;
                weakSelf.tableView.hidden=NO;
                [weakSelf.tableView.header endRefreshing];
                [weakSelf.tableView.header beginRefreshing];
            }
        };
        [self.view addSubview:_lotteryTypeView];
        
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [self.view addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.view);
            make.height.mas_equalTo(5);
            make.top.equalTo(weakSelf.twoAdvertisingView.mas_bottom);
        }];
        [_lotteryTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf.view);
            make.top.equalTo(view.mas_bottom);
            make.height.mas_equalTo(real_size(42));
        }];
    }
    return _lotteryTypeView;
}

- (NSMutableArray *)newTypeArr{
    if (!_newTypeArr) {
        _newTypeArr=[[NSMutableArray alloc]init];
    }
    return _newTypeArr;
}

- (UIButton *)navTitleBtn{
    NSString *title=@"";
    if ([InformationVM manage].lotteryTypeArr.count>self.selectLottery) {
        NewsLottryTypeModel *model=[InformationVM manage].lotteryTypeArr[self.selectLottery-1];
        title=model.LTypeName;
    }
    
    CGFloat width=[TGTools boundingRectWithString:title withWidth:300 anfont:[UIFont boldSystemFontOfSize:19]];
    
    UIButton *_navTitleBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, width+30, 30)];
    [_navTitleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _navTitleBtn.titleLabel.font=[UIFont boldSystemFontOfSize:19];
    [_navTitleBtn setTitle:title forState:UIControlStateNormal];
    [_navTitleBtn setImage:[UIImage imageNamed:@"white_angle"] forState:UIControlStateNormal];
    [_navTitleBtn verticalImageAndTitle:width andImage:[UIImage imageNamed:@"white_angle"]];
    _navTitleBtn.layer.masksToBounds=YES;
    _navTitleBtn.layer.cornerRadius=2;
    _navTitleBtn.layer.borderColor=[UIColor whiteColor].CGColor;
    _navTitleBtn.layer.borderWidth=1;
    [_navTitleBtn addTarget:self action:@selector(onclickType:) forControlEvents:UIControlEventTouchUpInside];
    return _navTitleBtn;
}

//- (AdvertisingView *)oneAdvertisingView{
//    if (!_oneAdvertisingView) {
//        WS(weakSelf);
//        _oneAdvertisingView =[[AdvertisingView alloc]init];
//        self.oneAdvertisingView.changeHeight = ^(float height) {
//            [weakSelf.oneAdvertisingView mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.height.mas_equalTo(@(height));
//            }];
//        };
//        [self.view addSubview:_oneAdvertisingView];
//        [_oneAdvertisingView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.top.equalTo(self.view);
//            make.height.mas_equalTo(@0);
//        }];
//
//    }
//    return _oneAdvertisingView;
//}

- (AdvertisingView *)twoAdvertisingView{
    if (!_twoAdvertisingView) {
        WS(weakSelf);
        _twoAdvertisingView =[[AdvertisingView alloc]init];
        self.twoAdvertisingView.changeHeight = ^(float height) {
            [weakSelf.twoAdvertisingView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(@(height));
            }];
        };
        [self.view addSubview:_twoAdvertisingView];
        [_twoAdvertisingView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.equalTo(self.view).offset(-10);
            make.left.equalTo(self.view).offset(10);
            make.top.equalTo(self.topView.mas_bottom).with.offset(5);
            make.height.mas_equalTo(@0);
        }];
    }
    return _twoAdvertisingView;
}


- (GalleryView *)galleryView{
    if (!_galleryView) {
        WS(weakSelf);
        _galleryView=[[GalleryView alloc]init];
        _galleryView.backgroundColor=DEFAULTBGCOLOR;
        [self.view addSubview:_galleryView];
        [_galleryView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(weakSelf.view);
            make.top.equalTo(self.lotteryTypeView.mas_bottom);
        }];
    }
    return _galleryView;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (LotteryVC *)lotteryVC{
    if (!_lotteryVC) {
        WS(weakSelf);
        [self.tableView reloadData];
        _lotteryVC=[[LotteryVC alloc]init];
        _lotteryVC.selectNav = ^(LotteryNavModel *model) {
            if (model.Type==1) {
                if ([model.Name isEqualToString:@"高手计划"]) {
                    MasterListVC *vc=[[MasterListVC alloc]init];
                    vc.lType=model.Id;
                    vc.strTitle=@"6彩";
                    [weakSelf.navigationController pushViewController:vc animated:YES];

                }else if ([model.Name isEqualToString:@"官方计划"]){
                    PlanVC *vc=[[PlanVC alloc]init];
                    LotteryTypeModel *typeModel=[[LotteryTypeModel alloc]init];
                    typeModel.lType=model.Id;
                    typeModel.Name=@"6彩";
                    typeModel.Id=model.Id;
                    vc.lotteryModel=typeModel;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }else{
                    OpenLotteryRecordVC *vc =[[OpenLotteryRecordVC alloc]init];
                    vc.lType=model.Id;
                    vc.title=[NSString stringWithFormat:@"6彩开奖记录"];
                    vc.lotteryType=LotteryNumTypeLottery;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }
                
            }else if (model.Type==2){
                InformationVC *vc=[[InformationVC alloc]init];
                vc.saveViewController=weakSelf.saveViewController;
                [vc setLotteryWithType:weakSelf.selectLottery andIndex:model.index];
                [weakSelf.navigationController pushViewController:vc animated:YES];
            }else if (model.Type==3){
                PublicWebVC *vc=[[PublicWebVC alloc]init];
                vc.url=model.Url;
                vc.title=@"六合彩-开奖时间";
                [weakSelf.navigationController pushViewController:vc animated:YES];
            }
        };
        _lotteryVC.selectType = ^(NewsTypeModel *model) {
            InformationVC *vc=[[InformationVC alloc]init];
            vc.saveViewController=weakSelf.saveViewController;
            [vc setLotteryWithType:weakSelf.selectLottery andIndex:model.index];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        };
        [self.view addSubview:_lotteryVC.view];
        [_lotteryVC.view setFrame:self.view.bounds];
        _lotteryVC.view.hidden=YES;
        [self addChildViewController:_lotteryVC];
    }
    return _lotteryVC;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
